|
|
|
|
|
|
|
two forms within the same screen. Usually, Subforms are used to combine standard form layout data entry screens with view-only or view and edit lists. For example, if you want to create a form that shows customer information (name, address, and so on) at the top of the form and a list of invoices outstanding for that customer at the bottom of the form, you have a Subform type entry screen. |
|
|
|
|
|
|
|
|
Typically, Subforms are used to display data tables linked through relationship definitions. In the case just mentioned, the customer information is probably in a single master table, and the invoice data is probably in a related list table that is linked through the customer ID or some other unique field. When you have these types of relationships, Subforms make an excellent way to present data. |
|
|
|
|
|
|
|
|
If you spend much time programming databases, you'll meet up with the need for a good Subform strategy. Let's go through the process of designing and coding a Subform using Visual Basic 5 data-bound controls, especially the data grid. |
|
|
|
|
|
|
|
|
For example, you have a database that already exists, CH1203.MDB, which contains two tables. The first table is called Header. It contains all the information needed to fill out a header on an invoice or monthly statement, such as CustID, CustName, Address, City, State, and Zip. There is also a table called SalesData. This table contains a list of each invoice currently on file for the customer, and it includes the CustID, Invoice Number, Invoice Description, and the Invoice Amount. The two tables are linked through the CustID field that exists in both tables. There is a one-to-many (Header-to-SalesData) relationship defined for the two tables. |
|
|
|
|
|
|
|
|
You need to design a form that allows users to browse through the master table (Header), displaying all the address information for review and update. At the same time, you need to provide the user with a view of the invoice data on the same screen. As the customer records are changed, the list of invoices must also be changed. You need a Subform. |
|
|
|
|
|
|
|
|
Laying Out and Coding the Subform with Visual Basic 5 |
|
|
|
|
|
|
|
|
Start a new project in Visual Basic 5. Lay out the Header table information at the top of the form and the SalesTable information in a grid at the bottom of the form. You need two data controls (one for the Header table and one for the SalesTable), one grid for the sales data, and several label and input controls for the Header data. Use Table 12.4 and Figure 12.22 as guides as you lay out the Subform. |
|
|
|
|
|